/*
 * EnigmaGM - A feature rich guild management system.
 * Copyright (C) 2007 ajiaojr.
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */
package org.ajiaojr.enigmagm.client;

import com.google.gwt.user.client.ui.Panel;

/**
 * <code>Paged</code> that allows the results to be sorted.
 * 
 * @author ajiaojr
 * @see org.ajiaojr.enigmagm.client.Paged
 */
public abstract class SortablePaged extends Paged {
  protected boolean ascending = true;

  protected String sortAttribute;

  public SortablePaged(Panel panel, int maxResults, String sortAttribute) {
    super(panel, maxResults);
    this.sortAttribute = sortAttribute;
  }

  /**
   * @return
   */
  public String getSortAttribute() {
    return sortAttribute;
  }

  /**
   * @param sortAttribute
   */
  public void setSortAttribute(String sortAttribute) {
    if (this.sortAttribute.equals(sortAttribute)) {
      this.ascending = !this.ascending;
    } else {
      this.sortAttribute = sortAttribute;
      this.ascending = true;
    }

    populate();
  }
}
